import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:inmotion_pro/config/r.dart';
import 'package:inmotion_pro/l10n/local.dart';
import 'package:inmotion_pro/pages/models/user_model.dart';
import 'package:lx_widgets_library/lx_widgets_library.dart';

// 车主信息视图
class OwnerInfoView extends StatelessWidget {
  // 用户模型
  final UserModel model;

  const OwnerInfoView({super.key, required this.model});

  @override
  Widget build(BuildContext context) {
    double imageSize = 40.w;
    return Row(
      children: [
        Padding(
          padding: EdgeInsets.only(left: CONTENT_MARGIN / 2),
          child: Container(
            color: Colors.transparent,
            alignment: Alignment.centerLeft,
            child: ClipRRect(
              borderRadius: BorderRadius.circular(imageSize / 2),
              child: model.avatar.isEmpty
                  ? Container(
                      width: imageSize,
                      height: imageSize,
                      color: GrayColor.gray3,
                      child: _defaultImage(
                        imageSize - 16.w,
                      ),
                    )
                  : AdvancedNetworkImage(
                      imageUrl: model.avatar,
                      width: imageSize,
                      height: imageSize,
                      placeholder: _defaultImage(imageSize),
                      fit: BoxFit.cover,
                    ),
            ),
          ),
        ),
        SizedBox(width: CONTENT_MARGIN),
        Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Container(
              width: 20.w,
              height: 20.w,
              decoration: BoxDecoration(
                color: LxCol.theme,
                borderRadius: BorderRadius.circular(12.w),
                border: Border.all(
                  color: Colors.white, // 边框颜色
                  width: 1.0, // 边框宽度
                ),
              ),
              child: Center(
                  child: LxText(
                local.primary,
                fontWeightEnum: LxFontWeightEnum.markSmall,
              )),
            ),
            SizedBox(height: 5.w),
            Container(
              constraints: BoxConstraints(
                maxWidth:
                    screenWidth - imageSize * 2 - 6 * CONTENT_MARGIN - 20.w,
              ),
              child: LxText(
                model.nickname.isEmpty ? model.name : model.nickname,
                color: Colors.white,
                fontWeightEnum: LxFontWeightEnum.bodyLarge,
              ),
            ),
          ],
        )
      ],
    );
  }

  // 默认应用图标
  Widget _defaultImage(double size) {
    return Center(
      child: Transform.translate(
        offset: const Offset(0, 0), // 向下偏移0像素
        child: Image.asset(
          R.unloginUserIcon,
          width: size - 16.w,
          fit: BoxFit.contain,
        ), // 你的组件
      ),
    );
  }
}
